package com.training.java.core.collections.car.post15;

/**
 * Create comparable interface. The purpose of this class is to observe how the
 * equals compare 2 strings. How instanceof is checking runtime objects.
 * instanceof will check the parameter that obj is real time object or not.
 * 
 */

public class Car implements Comparable<Car> {

	private String vinNumber;
	private String make;
	private String model;

	// Getter and Setters

	public String getVinNumber() {
		return vinNumber;
	}

	public String getMake() {
		return make;
	}

	public String getModel() {
		return model;
	}

	// Creating the constructor
	public Car(String vinNumber, String make, String model)

	{
		this.vinNumber = vinNumber;
		this.make = make;
		this.model = model;
	}

	// Constructor for mutable objects

	public Car() {

	}

	/**
	 * Here the requirement is "If make,model are equal the cars are equal"
	 * finding the equality by overriding the equals and hashCode
	 */

	@Override
	public boolean equals(Object obj) {

		// Instanceof-- checking the parameter is real time object Car or not.
		// If it is not real Car object, it should
		// return False.

		if (obj instanceof Car)

		{
			Car car2 = (Car) obj; // Casting
			return this.make.equals(car2.make) && this.model.equals(car2.model);

		} else {
			return false;

		}

	}// end of equals method

	// Overriding the hashCode

	@Override
	public int hashCode() {
		return vinNumber.hashCode() + make.hashCode() + model.hashCode();
	}

	/**
	 * compareTo method for TreesetDemo
	 * 
	 */

	// Overriding Compare to method.

	@Override
	public int compareTo(Car that) {

		return this.make.compareTo(that.make);
	}

}
